package com.gitee.sparta.pressure;

import com.alibaba.fastjson.JSON;
import com.gitee.sparta.annotation.SpartaListener;
import com.gitee.sparta.pressure.entity.PressureTest1Entity;
import com.gitee.sparta.pressure.entity.PressureTest2Entity;
import com.gitee.sparta.pressure.entity.PressureTest3Entity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 *
 * </p>
 *
 * @author zyred
 * @since v 0.0.1
 */
@Slf4j
//@Component
public class PressureListener {

    @SpartaListener(topics = PressureTestConstants.PRESSURE_TEST_1)
    public void handler1(PressureTest1Entity entity) throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        log.info("{} : entity : {}", PressureTestConstants.PRESSURE_TEST_1, JSON.toJSONString(entity));
    }

    @SpartaListener(topics = PressureTestConstants.PRESSURE_TEST_2)
    public void handler2(PressureTest2Entity entity) throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        log.info("{} : entity : {}", PressureTestConstants.PRESSURE_TEST_2, JSON.toJSONString(entity));
    }

    @SpartaListener(topics = PressureTestConstants.PRESSURE_TEST_3)
    public void handler3(PressureTest3Entity entity) throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        log.info("{} : entity : {}", PressureTestConstants.PRESSURE_TEST_3, JSON.toJSONString(entity));
    }

}
